<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:p="http://primefaces.prime.com.tr/ui"
                xmlns:c="http://java.sun.com/jsf/composite/componentes"
                template="../template.xhtml">
    <ui:define name="conteudo">

        <h:form id="formEditarEvento" styleClass="form-estilo" prependId="false" rendered="#{listarMembro.autorizar('PAPEL_EDITAR_EVENTO')}">
            <h2>#{i18n.evento_titulo_editar}</h2>
            <fieldset>
                <legend>Detalhes</legend>
                <c:edicao controle="#{editarEvento}" textoBotaoVoltar="#{i18n.botao_voltar}" textoBotaoSalvar="#{i18n.botao_salvar}"/>
                <br/><br/>
                <h:panelGrid columns="2">
                    <h:outputLabel value="#{i18n.evento_nome}"/>
                    <h:inputText value="#{editarEvento.objeto.nome}" size="50"/>
                    <h:outputLabel value="#{i18n.evento_data}"/>
                    <p:calendar value="#{editarEvento.objeto.data}" title="Escolha a data" pattern="dd/MM/yyyy">
                        <f:convertDateTime type="date" dateStyle="short" pattern="dd/MM/yyyy"/>
                    </p:calendar>
                </h:panelGrid>
                <br/>
                <p:tabView rendered="#{editarEvento.objeto.id != null}">
                    <p:tab title="#{i18n.evento_ministracao}">

                        <h:commandButton styleClass="commandButton" value="Incluir" onclick="painelEditarMinistracao.show()">
                            <f:setPropertyActionListener target="#{editarMinistracao.objeto.evento}" value="#{editarEvento.objeto}"/>
                            <f:ajax execute="@this"/>
                        </h:commandButton>

                        <p:dataTable id="dataTableMinistracao"
                                     var="ministracao"
                                     value="#{editarEvento.objeto.ministracoes}"
                                     paginator="true" rows="5"
                                     firstPageLinkLabel="Primeiro"
                                     previousPageLinkLabel="Anterior"
                                     nextPageLinkLabel="Próximo"
                                     lastPageLinkLabel="Último">
                            <p:column width="400">
                                <f:facet name="header">
                                    <h:outputText value="#{i18n.ministracao_musica}"/>
                                </f:facet>
                                <h:outputText value="#{ministracao.musica.nome}"/>
                            </p:column>
                            <p:column>
                                <f:facet name="header">
                                    <h:outputText value="Remover"/>
                                </f:facet>
                                <h:commandLink actionListener="#{editarEvento.removerMinistracao(ministracao)}">
                                    <f:ajax execute="dataTableMinistracao" render="@form"/>
                                    <h:graphicImage style="border: 0px;" value="#{resource['img:remover.png']}"/>
                                </h:commandLink>
                            </p:column>
                        </p:dataTable>



                    </p:tab>                    
                </p:tabView>
            </fieldset>
        </h:form>

        <p:dialog widgetVar="painelEditarMinistracao" 
                  onCloseUpdate="formEditarEvento"
                  header="Editar Ministração"
                  fixedCenter="true"
                  effect="FADE"
                  width="480px"
                  height="250px">
            <ui:include id="pagina" src="/cadastro/editarMinistracao.xhtml"/>
        </p:dialog>

    </ui:define>
</ui:composition>